package gestionSimpleATester;

import java.util.Collection;
import java.util.Vector;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;


public class PersonWithAccountTest {
	Person p;
	Account a;
	@Before
	public void setUp(){
		p =new Person("Mr Person");
		a = new Account(p,0,0,1);
	}
	@After
	public void tearDown(){
		p = null;
	}
	@Test
	public void ConstructorTest(){
		p = new Person("Some Body");
		Assert.assertNotNull(p);
	}
	
	@Test
	public void get_SetNameTets(){
		/***the getter and setter are suppose to be correct from the 
		 * case test in PersonTest.java
		 */
		p = new Person("any body");
		Assert.assertEquals(p.getName(), "any body");
		p.setName("need some body");
		Assert.assertEquals(p.getName(), "need some body");
		p.setName(null);
		Assert.assertEquals(p.getName(), null);
	}
	
	@Test
	public void accountSizeTest(){
		
	}
	
	@Test
	public void addAccountTest(){
		p.addAccounts(a);
		/***Verifying the correct value***/
		Assert.assertTrue(p.getAccounts().contains(a));
		Assert.assertTrue(p.accountsSize()==1);
		
	}
	
	@Test
	public void getAccountTest(){
		p.addAccounts(a);
		Account a1 = new Account(p,10,10,10);
		p.addAccounts(a1);
		Assert.assertFalse(p.getAccounts().isEmpty());
		Assert.assertTrue(p.getAccounts().contains(a));
		Assert.assertTrue(p.getAccounts().contains(a1));
			
	}
	@Test
	public void setAccountTest(){
		Vector v = new Vector();
		v.add(a);
		v.add(new Account(p,10,10,10));
		p.setAccounts(v);
		Assert.assertFalse(p.getAccounts().isEmpty());
		Assert.assertEquals(p.getAccounts().size(), 2);
		Assert.assertTrue(p.getAccounts().contains(a));
		Assert.assertFalse(p.getAccounts().contains(new Account(p,100,100,100)));
	}
	
	@Test
	public void removeAccountTest(){
		p.addAccounts(a);
		System.out.println("size __ "+p.getAccounts().size());
		p.removeAccounts(a);
		System.out.println("size __ "+p.getAccounts().size());
		Assert.assertEquals(p.getAccounts().size(), 0);
		Assert.assertNull(p.getAccounts());
	}
	
}
